<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    </style>
</head>
<body>
<div id="root">
</div>
<script>
    let str = 'aabccd';

    function strArr(str) {
        return str.split('');
    }

    // 统计字符串出现次数
    function stat(str) {
        let str_Arr = strArr(str)
        let oldStr = new Set(str_Arr);
        let newStr = []
        let i = 0;
        oldStr.forEach(val => {
            let j = 0;
            str_Arr.forEach(elem => {
                if (elem === val) {
                    newStr[i] = val + ' ' + ++j;
                }
            });
            i++;
        })
        return newStr;
    }


    console.log(stat(str));
    console.log(new Set(str));
</script>

</body>
</html>